package com.linxiao.hrcrm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.linxiao.hrcrm.domain.CrmCustomerRelationship;
import com.linxiao.hrcrm.service.ICrmCustomerRelationshipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户关系Controller
 * 
 * @author zhoudong
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/hrcrm/relationship")
public class CrmCustomerRelationshipController extends BaseController
{
    @Autowired
    private ICrmCustomerRelationshipService crmCustomerRelationshipService;

    /**
     * 查询客户关系列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:relationship:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerRelationship crmCustomerRelationship)
    {
        startPage();
        List<CrmCustomerRelationship> list = crmCustomerRelationshipService.selectCrmCustomerRelationshipList(crmCustomerRelationship, Boolean.TRUE);
        return getDataTable(list);
    }

    /**
     * 导出客户关系列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:relationship:export')")
    @Log(title = "客户关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCustomerRelationship crmCustomerRelationship)
    {
        List<CrmCustomerRelationship> list = crmCustomerRelationshipService.selectCrmCustomerRelationshipList(crmCustomerRelationship, Boolean.FALSE);
        ExcelUtil<CrmCustomerRelationship> util = new ExcelUtil<CrmCustomerRelationship>(CrmCustomerRelationship.class);
        util.exportExcel(response, list, "客户关系数据");
    }

    /**
     * 获取客户关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:relationship:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(crmCustomerRelationshipService.selectCrmCustomerRelationshipById(id));
    }

    /**
     * 新增客户关系
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:relationship:add')")
    @Log(title = "客户关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerRelationship crmCustomerRelationship)
    {
        return toAjax(crmCustomerRelationshipService.insertCrmCustomerRelationship(crmCustomerRelationship));
    }

    /**
     * 修改客户关系
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:relationship:edit')")
    @Log(title = "客户关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerRelationship crmCustomerRelationship)
    {
        return toAjax(crmCustomerRelationshipService.updateCrmCustomerRelationship(crmCustomerRelationship));
    }

    /**
     * 删除客户关系
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:relationship:remove')")
    @Log(title = "客户关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmCustomerRelationshipService.deleteCrmCustomerRelationshipByIds(ids));
    }
}
